<?php
namespace app\index\controller;

use think\Controller;
use think\View;
use Wechat\TPWechat;

class CheckMember extends Common {

    public function _initialize() {
        parent::_initialize();
        if ($_SERVER['HTTP_HOST'] != 'localhost:8078') {
            // 检查登录状态
            if (!session('?member_id') || !session('?member_username')) {
                if (!session('?openid')) {
                    $this->oauth();  // 获取授权
                } else {
                    $member = model('Member')->get(['openid' => session('openid')]);  // 获取绑定脏户信息
                    if ($member) {  // 记录session
                        session('member_id', $member['id']);
                        session('member_username', $member['username']);
                    } else{  // 跳转到绑定页面
                        $this->redirect('login/index');
                    }
                }
            }
        } ELSE {
            session('openid', 'o_WIcwccOaW-UdBrgeyDofcw5qO4');
            session('member_id', 501);
            session('member_username', '15802571830');
        }
    }
}
